%Resamples the particles, based on the reweighted particles.
%Returns a new set of particles.
function new_particles = resample(particles, map)
    particles = particles(1:round(end/5),:);
    max_particles = 100.^2; %remember to change in initialise too
    
    selected_particles = particles(randsample(1:size(particles, 1), max_particles, true, particles(:, 4)), :);
    new_particles = create_particles_from_states(selected_particles(:, 1:3), selected_particles(:, 4), map);
    return
end